package com.apps.helper;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * python帮助类
 */
public class PythonHelper {

    /**
     * 执行python脚本
     * @param path
     * @return
     */
    public static String excutePython(String path)
    {
        String result="";
        Process proc;
        try {
            proc = Runtime.getRuntime().exec(path);
            BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream(),"GB2312"));
            String line = null;
            while ((line = in.readLine()) != null) {
                result+=line;
            }
            in.close();
            proc.waitFor();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return result;
    }
}
